package com.socialuni.center.web.controller.login;

import com.socialuni.sdk.api.model.ResultRO;
import com.socialuni.center.web.model.RO.CenterLoginRO;
import com.socialuni.center.web.model.RO.user.CenterMineUserDetailRO;
import com.socialuni.center.web.user.login.CenterLoginService;
import com.socialuni.sdk.model.BindPhoneVO;
import com.socialuni.sdk.model.ProviderLoginQO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author qinkaiyuan
 * @date 2019-02-17 14:14
 */
@RestController
@RequestMapping("socialuni/login")
@Slf4j
public class LoginController {
    @Resource
    private CenterLoginService centerLoginService;

    //三方渠道登录，qq、wx、社交联盟，兼容各平台，h5、app、mp
    @PostMapping("providerLogin")
    @ResponseBody
    public ResultRO<CenterLoginRO<CenterMineUserDetailRO>> providerLogin(@RequestBody ProviderLoginQO loginData) {
        CenterLoginRO<CenterMineUserDetailRO> socialUserDetailRO = centerLoginService.providerAndPhoneLogin(loginData, null);
        return new ResultRO<>(socialUserDetailRO);
    }

    @PostMapping("phoneLogin")
    @ResponseBody
    public ResultRO<CenterLoginRO<CenterMineUserDetailRO>> phoneLogin(@RequestBody BindPhoneVO bindPhoneVO) {
        CenterLoginRO<CenterMineUserDetailRO> socialUserDetailRO = centerLoginService.providerAndPhoneLogin(null, bindPhoneVO);
        return new ResultRO<>(socialUserDetailRO);
    }
}
